<template>
  <div class="detail">
    <!-- 搜索 -->
    <van-sticky>
      <van-search
        v-model="value"
        placeholder="请输入搜索关键词"
        shape="round"
        background="#d43c33"
        @focus="iptBtn()"
      />
    </van-sticky>
    <!-- 轮播 -->
    <div class="Mswiper">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="item in banners" :key="item.id">
          <img :src="item.imageUrl" alt="" class="bannerImg" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <van-tabs
      v-model="active"
      sticky
      animated
      swipeable
      line-width="50px"
      line-height="2px"
      background="#fff"
      border
      title-active-color="#dd001b"
      offset-top="50"
    >
      <van-tab title="推荐音乐" class="van-tabone">
        <div class="Mtitle">
          <div class="Micon"></div>
          <div class="Mtitletxt">编辑推荐</div>
        </div>
        <div class="MsongBox">
          <div class="MsongList" v-for="item in hotMusics" :key="item.id">
            <div>
              <img :src="item.picUrl" alt="" />
            </div>
            <div>{{ item.name }}</div>
          </div>
        </div>
        <div class="Mtitle">
          <div class="Micon"></div>
          <div class="Mtitletxt">最新音乐</div>
        </div>
        <div
          class="MnawsongBox"
          v-for="(item, index) in newMusicList"
          :key="index"
        >
          <div class="MnawsongBoxlist">
            <div>
              {{ item.name }}<span>{{ item.alia[0] }}</span>
            </div>
            <div>
              <i class="u-hmsprt sghot"></i>{{ item.ar[0].name }}-
              {{ item.name }}
            </div>
          </div>
          <div class="iconsong"></div>
        </div>
      </van-tab>
      <van-tab title="热歌榜">内容 2</van-tab>
      <van-tab title="原创榜">内容 3</van-tab>
      <van-tab title="新歌榜">内容 4</van-tab>
    </van-tabs>
  </div>
</template>

<script>
import axios from "axios";
import {
  Swipe,
  SwipeItem,
  Button,
  Search,
  Grid,
  GridItem,
  Icon,
  Tab,
  Tabs,
  Sticky,
} from "vant";
export default {
  components: {
    [Button.name]: Button,
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem,
    [Grid.name]: Grid,
    [Search.name]: Search,
    [GridItem.name]: GridItem,
    [Icon.name]: Icon,
    [Tabs.name]: Tabs,
    [Tab.name]: Tab,
    [Sticky.name]: Sticky,
  },
  data() {
    return {
      value: "",
      banners: [],
      active: 0,
      hotMusics: [],
      newMusicListurl: "",
      newMusicList: [],
    };
  },
  methods: {
    iptBtn() {
      this.$router.push({ path: "/Msecrah" });
    },
    getHotmusic() {
      // 轮播图
      axios({
        url: "https://autumnfish.cn/banner?type=0",
        method: "post",
      })
        .then((res) => {
          this.banners = res.data.banners;
        })
        .catch((err) => {
          console.log(err);
        });
      //热门歌曲
      axios({
        url: "https://autumnfish.cn/personalized?limit=6",
        method: "get",
      })
        .then((res) => {
          this.hotMusics = res.data.result;
        })
        .catch((err) => {
          console.log(err);
        });
      //最新音乐
      axios({
        url: "https://autumnfish.cn/playlist/detail/dynamic?id=3779629",
        method: "get",
      })
        .then((res) => {
          this.newMusicListurl = res.data.playlist.coverImgUrl;
          this.newMusicList = res.data.playlist.tracks.slice(0, 10);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  mounted() {
    this.getHotmusic();
  },
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.detail {
  background: #fcfcfd;
  /* height: 2000px; */
}
.bannerImg {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
}
.Mswiper {
  padding: 20px 12px 15px 12px;
  overflow: hidden;
}
.Mtitle {
  display: flex;
  align-items: center;
  height: 50px;
}
.Micon {
  width: 2px;
  height: 20px;
  background-color: #d33a31;
}
.Mtitletxt {
  font-size: 16px;
  color: #333;
  margin-left: 10px;
}
.MsongBox {
  width: 100%;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.MsongList {
  width: 32.5%;
  display: flex;
  flex-direction: column;
  margin-bottom: 15px;
}
.MsongList div:first-child img {
  width: 100%;
}
.MsongList div:last-child {
  width: 95%;
  display: -webkit-box;
  font-size: 13px;
  color: #333;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.MnawsongBox {
  width: 100%;
  padding-left: 14px;
  position: relative;
}
.MnawsongBoxlist {
  width: 100%;
  padding: 10px 0;
  border-bottom: 1px solid #efeff0;
}
.MnawsongBoxlist div:first-child {
  width: 80%;
  font-size: 17px;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.MnawsongBoxlist div:first-child span {
  color: #888;
  margin-left: 4px;
  font-size: 16px;
}
.MnawsongBoxlist div:last-child {
  color: #888;
  font-size: 12px;
  margin-top: 3px;
}
.sghot {
  display: inline-block;
  width: 12px;
  height: 8px;
  margin-right: 4px;
  background: url(../assets/image/index_icon_2x.png) no-repeat;
  background-size: 166px 97px;
}
.iconsong {
  width: 24px;
  height: 24px;
  background: url(../assets/image/index_icon_2x.png) no-repeat;
  background-position: -24px 0;
  background-size: 166px 97px;
  position: absolute;
  top: 20px;
  right: 30px;
}
.MnawsongBox:last-child {
  margin-bottom: 50px;
}
</style>